package com.mkb.service.impl;

import java.util.List;
import java.util.Map;

import com.mkb.entity.GraphClueDO;
import com.mkb.entity.GraphClueDTO;
import com.mkb.utils.MapUtils;
import com.zz.common.util.ObjectUtils;
import com.zz.common.validator.Assert;
import com.zz.common.validator.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mkb.dao.GraphClueDAO;
import com.mkb.service.GraphClueService;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class GraphClueServiceImpl implements GraphClueService {
	@Autowired
	private GraphClueDAO graphClueDAO;

	@Override
	public Boolean deleteById(Long id) {
		graphClueDAO.deleteById(id);
		return true;
	}

	@Override
	public Long create(GraphClueDTO record) throws Exception {
		GraphClueDO entity = record.clone(GraphClueDO.class);
		graphClueDAO.insert(entity);
		return entity.getId();
	}

	@Override
	public GraphClueDTO getById(Long id) throws Exception{
		Assert.isNull(id, "id 不能为空");
		GraphClueDO entity= graphClueDAO.getById(id);
		Assert.isNull(entity, "对象不存在");
		GraphClueDTO dto = entity.clone(GraphClueDTO.class);
		return dto;
	}

	@Override
	public Boolean update(GraphClueDTO record) throws Exception {
		Assert.isNull(record, "对象不存在");
		Assert.isNull(record.getId(), "对象id不存在");
		GraphClueDO entity = record.clone(GraphClueDO.class);
		graphClueDAO.update(entity);
		return true;
	}

	@Override
	public PageInfo<GraphClueDTO> queryPage(GraphClueDTO graphClueDTO) throws Exception {
	        ValidatorUtils.validateProperty(graphClueDTO, "pageNum", "pageSize");
		PageHelper.startPage(graphClueDTO.getPageNum(), graphClueDTO.getPageSize());
		List<GraphClueDO> graphClueDOS = graphClueDAO.queryList(MapUtils.parseMap(graphClueDTO));
		List<GraphClueDTO> graphClueDTOList = ObjectUtils.convertList(graphClueDOS, GraphClueDTO.class);
		return new PageInfo<>(graphClueDTOList);
	}

	@Override
	public List<GraphClueDTO> queryList(GraphClueDTO graphClueDTO) throws Exception {
		List<GraphClueDO> graphClueDOS = graphClueDAO.queryList(MapUtils.parseMap(graphClueDTO));
		List<GraphClueDTO> graphClueDTOList = ObjectUtils.convertList(graphClueDOS, GraphClueDTO.class);
		return graphClueDTOList;
	}

	@Override
	public int count(Map<String, Object> map) throws Exception {
		return graphClueDAO.count(map);
	}

	@Override
	public int deleteByGraphId(Long graphId) throws Exception {
		return graphClueDAO.deleteByGraphId(graphId);
	}

	@Override
	public void createBatch(List<GraphClueDTO> graphClueList) throws Exception {
		graphClueDAO.insertBatch(ObjectUtils.convertList(graphClueList, GraphClueDO.class));
	}

}